#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int n,kkk[15]={0,1,10,100,1000,10000};
struct ssbb
{
	int k,a,b,c,d,e;
}s[1005];
struct sssbbb
{
	int ak,now;
	string hh;
}ans[1005];
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string st,st1;
		cin>>st;
		if(st=="Server")s[i].k=1;
		else if(st=="Client")s[i].k=2;
		cin>>st1;
		int l=st1.size()-1,f=0,t1=1,t2[105]={0};
		char kk[105][105];
		for(int j=0;j<=l;j++)
		{
			if(st1[j]<48||st1[j]>57)
			{
				t1++;
				if(st1[j]!='.'&&t1<5)f=1;
				else if(st1[j]!=':'&&t1==5)f=1;
			}
			else 
			{
				t2[t1]++;
				kk[t1][t2[t1]]=st1[j];
			}
		}
		if(t2[1]>3||t2[2]>3||t2[3]>3||t2[4]>3||t2[5]>6)f=1;
		else if(t2[1]==3&&st1[0]>=51)f=1;
		else if(t2[2]==3&&st1[t2[1]+1]>=51)f=1;
		else if(t2[3]==3&&st1[t2[1]+t2[2]+2]>=51)f=1;
		else if(t2[4]==3&&st1[t2[1]+t2[2]+t2[3]+3]>=51)f=1;
		else if(t2[5]==5&&st1[t2[1]+t2[2]+t2[3]+t2[4]+4]>=55)f=1;
		else if(t2[1]!=1&&st1[0]==48)f=1;
		else if(t2[2]!=1&&st1[t2[1]+1]==48)f=1;
		else if(t2[3]!=1&&st1[t2[1]+t2[2]+2]==48)f=1;
		else if(t2[4]!=1&&st1[t2[1]+t2[2]+t2[3]+3]==48)f=1;
		else if(t2[5]!=1&&st1[t2[1]+t2[2]+t2[3]+t2[4]+4]==48)f=1;
		if(f==1)
		{
			s[i].k=-1;
			ans[i].now=1;
			ans[i].hh="ERR";
			continue;	
		}
		for(int j=0;j<t2[1];j++)s[i].a+=(st1[j]-48)*kkk[t2[1]-j];
		for(int j=0;j<t2[2];j++)s[i].b+=(st1[j+t2[1]+1]-48)*kkk[t2[2]-j];
		for(int j=0;j<t2[3];j++)s[i].c+=(st1[j+t2[1]+t2[2]+2]-48)*kkk[t2[3]-j];
		for(int j=0;j<t2[4];j++)s[i].d+=(st1[j+t2[1]+t2[2]+t2[3]+3]-48)*kkk[t2[4]-j];
		for(int j=0;j<t2[5];j++)s[i].e+=(st1[j+t2[1]+t2[2]+t2[3]+t2[4]+4]-48)*kkk[t2[5]-j];
	}
	for(int i=2;i<=n;i++)
	{
		if(s[i].k==2||s[i].k==-1)continue;
		for(int j=1;j<=i-1;j++)
		{
			if(s[i].k==1||s[i].k==-1)continue;
			if(s[i].a==s[j].a&&s[i].b==s[j].b&&s[i].c==s[j].c&&s[i].d==s[j].d&&s[i].e==s[j].e)
			{
				ans[i].now=1;
				ans[j].now=1;
				ans[i].hh="OK";
				ans[j].ak=i;
				break;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(ans[i].now==1)
		{
			if(ans[i].ak!=0)cout<<ans[i].ak<<endl;
			else cout<<ans[i].hh<<endl;
		}
		else cout<<"FAIL"<<endl;
	}
	return 0;
}


